<head th:include="certificateWeb/headFoot :: headerCss"></head>
<link href="/css/certificateWeb/login.css" rel="stylesheet">
<div th:include="certificateWeb/headFoot :: header"></div>
<style type="text/css">
</style>
<body class="signin">
<div class="signinpanel">
    <!--<h1 style="text-align: center;font-size: 42px"><a style="color: #fff" href="/certificate/homepage">湖南金职伟业证书信息平台</a></h1>-->
    <div class="row">
        <div class="login_panel">
            <div class="div-1">
                <h3 class="title">用户登录</h3>
                <div class="box_1">
                    <label class="label">&nbsp;用户名：</label>&nbsp;&nbsp;
                    <label class="label"><input style="color: #555555 ;" type="text" name="username" id="name"
                                                class="form-control reg_web" placeholder="用户名"/></label>
                </div>
                <div class="box_1">
                    <label class="label">&nbsp;密&nbsp;&nbsp;&nbsp;&nbsp;码：</label>&nbsp;&nbsp;
                    <label class="label"><input style="color: #555555 ;" type="password" name="password" id="password"
                                                class="form-control reg_web" placeholder="密码"/></label><br/>
                </div>
                <div class="reg">
                    <label class="label"><a style="color:#666; margin-left:16px" href="/certificate/forgetPass">忘记密码</a></label>
                    <label class="label"><a style="color:#005C34; margin-right: 15px" href="/certificate/registerWeb">立即注册</a></label>
                    <label class="label"><a style="color:#005C34; margin-right: 15px" th:href="${url}">扫一扫登录</a></label>
                </div>
                <button class="btn btn-login" style="margin: 10px auto 30px 45px" onclick="login();">登录</button>
            </div>
        </div>
    </div>
</div>
<div th:include="certificateWeb/headFoot :: footer"></div>
<script src="/js/plugins/layer/layer.min.js" th:src="@{/js/plugins/layer/layer.min.js}"></script>
<script type="text/javascript">
    //回车登录
    document.onkeydown = cdk;

    function cdk() {
        if (event.keyCode == 13) {
            login();
        }
    }

    function login() {
        var username = $("#name").val();
        var password = $("#password").val();
        if ('' == username) {
            layer.msg('请输入用户名');
            return false
        }
        if ('' == password) {
            layer.msg('请输入密码');
            return false
        }
        $.ajax({
            type: "POST",
            url: "/certificate/sendLogin",
            data: {username: username, password: password},
            success: function (r) {
                // console.log("rrrr = " , r );
                // console.log("document.referrer",document.referrer)
                if (r.code == 0) {
                    window.localStorage.setItem("userName", r.data.userName);
                    window.localStorage.setItem("token", r.data.token);
                    window.localStorage.setItem("unreadNum0", r.data.unreadNum0);
                    window.localStorage.setItem("unreadNum1", r.data.unreadNum1);
                    if (r.data.type != 1){
                        if (document.referrer != '') {
                            if (document.referrer.indexOf('forgetPass') != -1 || document.referrer.indexOf('registerWeb') != -1) {
                                location.href = '/certificate/homepage'
                            } else {
                                location.href = document.referrer
                            }
                        } else {
                            location.href = '/certificate/homepage'
                        }
                    }else {
                        if (r.data.uName == null){
                            layer.confirm('系统检测到您为机构会员，请前往个人中心完善个人和机构信息', {
                                closeBtn: 0,
                                btn : ['立即前往']
                            }, function() {
                                location.href = '/certificate/my'
                            })
                        }else {
                            if (document.referrer != '') {
                            if (document.referrer.indexOf('forgetPass') != -1 || document.referrer.indexOf('registerWeb') != -1) {
                                location.href = '/certificate/homepage'
                            } else {
                                    location.href = document.referrer
                            }
                            } else {
                                location.href = '/certificate/homepage'
                            }
                        }
                    }
                } else {
                    layer.msg(r.msg);
                }
            }
        });
    }

</script>
</body>





